//
//  MainViewController.m
//  shusheng
//
//  Created by rimi on 16/7/9.
//  Copyright © 2016年 yuying. All rights reserved.
//

#import "MainViewController.h"

#import "CDFriendListVC.h"

@interface MainViewController ()
@property (strong,nonatomic) UIImageView *backgroundImg;
@property (nonatomic,strong) EssayViewController *essayVC;
@property (nonatomic,strong) NovelViewController *novelVC;
//@property (nonatomic,strong) FriendsViewController *friendsVC;
@property (nonatomic,strong) BlackRoomViewController *blackRoomVC;
@property (nonatomic,strong) CommunityViewController *communityVC;
@property (nonatomic,strong) MineViewController *mineVC;
@property (nonatomic,strong) CDFriendListVC *friendsVC;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"主视图");
    self.view.backgroundColor = [UIColor whiteColor]; 
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    _essayVC = [story instantiateViewControllerWithIdentifier:@"EssayViewController"];
    _novelVC = [story instantiateViewControllerWithIdentifier:@"NovelViewController"];
//    _friendsVC = [story instantiateViewControllerWithIdentifier:@"FriendsViewController"];
    _blackRoomVC = [story instantiateViewControllerWithIdentifier:@"BlackRoomViewController"];
    _communityVC = [story instantiateViewControllerWithIdentifier:@"CommunityViewController"];
    _mineVC = [story instantiateViewControllerWithIdentifier:@"MineViewController"];
        _friendsVC = [[CDFriendListVC alloc] init];
 
    [self initializeUserInterface];
}

- (void)initializeUserInterface{
    [self.view addSubview:self.backgroundImg];
    [self btn:@"文章编辑" center:CGPointMake(SCREEN_WIDTH/3, SCREEN_HEIGHT/4) tag:TAG_BTN+0];
    [self btn:@"小说编辑" center:CGPointMake(SCREEN_WIDTH*2/3, SCREEN_HEIGHT/4) tag:TAG_BTN+1];
    [self btn:@"好友"    center:CGPointMake(SCREEN_WIDTH/3, SCREEN_HEIGHT/2) tag:TAG_BTN+2];
    [self btn:@"小黑屋"  center:CGPointMake(SCREEN_WIDTH*2/3, SCREEN_HEIGHT/2) tag:TAG_BTN+3];
    [self btn:@"社区"   center:CGPointMake(SCREEN_WIDTH/3, SCREEN_HEIGHT*3/4) tag:TAG_BTN+4];
    [self btn:@"我的"  center:CGPointMake(SCREEN_WIDTH*2/3, SCREEN_HEIGHT*3/4) tag:TAG_BTN+5];
    

    
}
- (void)btn:(NSString*)btnTitle
      center:(CGPoint)center
        tag:(NSInteger)tag{
    
    UIButton * btn = [UIButton createButton:CGRectMake(0, 0, SCREEN_WIDTH/4, SCREEN_WIDTH/4) center:center color:RGB_COLOR(237, 102, 11, 0.9) cornerRadius:SCREEN_WIDTH/8 masksToBounds:YES title:btnTitle tag:tag];
    [btn addTarget:self action:@selector(respondsToBtn:) forControlEvents: UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}

- (void)respondsToBtn:(UIButton *)sender{
    _buttonFrame = sender.frame;
    switch (sender.tag - TAG_BTN) {
         
        case 0:
            NSLog(@"文章编辑");
            [self presentViewController:_essayVC animated:YES completion:nil];
            break;
        case 1:
            NSLog(@"小说编辑");
            [self presentViewController:_novelVC animated:YES completion:nil];
            break;
            
        case 2:
            NSLog(@"好友");
            [self presentViewController:_friendsVC animated:YES completion:nil];
            break;
        case 3:
            NSLog(@"小黑屋");
           [self presentViewController:_blackRoomVC animated:YES completion:nil];
            break;
        case 4:
            NSLog(@"社区");
            [self presentViewController:_communityVC animated:YES completion:nil];
            break;
        case 5:
            NSLog(@"我的");
            [self presentViewController:_mineVC animated:YES completion:nil];
            break;
        
        default:
            break;
    }
    

}


-(UIImageView *)backgroundImg{
    if (!_backgroundImg) {
        _backgroundImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"main.jpeg"]];
        _backgroundImg.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
    }
    return _backgroundImg;
}




@end
